package com.arrogames.blondbattle.game.graphics.ui 
{
	import com.arrogames.blondbattle.game.state.Money;
	import com.arrogames.util.Observable;
	import com.arrogames.util.Observer;
	import feathers.controls.Label;
	import starling.display.Sprite;
	import starling.events.Event;
	
	/**
	 * ...
	 * @author Robin van den Bogaard
	 */
	public class MoneyLabel extends Sprite implements Observer {
		private var labelDisplay:Label;
		private var money:Money;
		
		public function MoneyLabel(money:Money) {
			super();
			
			this.money = money;
			this.money.addObserver(this);
			
			this.labelDisplay = new Label();
			this.labelDisplay.text = format(money.value);
			this.addChild(labelDisplay);
		}
		
		override public function dispose():void {
			super.dispose();
			money.deleteObserver(this);
			money = null;
		}
		
		private function format(value:Number):String {
			return  value + "$";
		}
		
		/* INTERFACE com.arrogames.util.Observer */
		public function update(obs:Observable, obj:Object):void {
			var money:Money = obs as Money;
			labelDisplay.text = format(money.value);
		}
		
	}

}